package bmp
{
	import flash.display.*;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.*;
	import flash.geom.*;
	import flash.ui.Keyboard;
	
	import kim.math.ui.PlaneUI;

	public class Plane extends Sprite
	{
		private var backBuffer:BitmapData=new BitmapData(550,400,false);//建立一个缓冲区
		private var clearColor:uint=0xFFFFFF;//指定填充的颜色
		private var myplane:PlaneUI=new PlaneUI(59,43);//我们在flash 库里面的资源,是bitmapdata的一个子类
		private var position:Point=new Point(250,200);// 指定像素位置 
		public function Plane()
		{
			
			addEventListener(Event.ENTER_FRAME,Run);
			stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDown);
		}
		private function init():void
		{
			backBuffer.fillRect(backBuffer.rect, clearColor);//填充
			backBuffer.copyPixels(myplane,myplane.rect, position, myplane.bitmapAlpha, new Point(0, 0), true);
			var iamge:Sprite=new Sprite();//建立一个位图
			addChild(iamge);//显示位图
			iamge.graphics.clear();
			iamge.graphics.beginBitmapFill(backBuffer, null, false, false);//使用 填充位图的方法 填充缓冲区
			iamge.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);//画出矩形
			iamge.graphics.endFill();//结束填充
		}
		private function Run(e:Event):void
		{
			init();
			
		}
		private function keyDown(e:KeyboardEvent):void
		{
			if (e.keyCode==Keyboard.UP)
			{
				position.y-=5;
			}
			else if (e.keyCode==Keyboard.DOWN)
			{
				position.y+=5;
			}
			else if (e.keyCode==Keyboard.LEFT)
			{
				position.x-=5;
			}
			else if (e.keyCode==Keyboard.RIGHT)
			{
				position.x+=5;
			}
		}
	}
}